﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using nwrole.Orchestrator.site.Models;
using nwrole.Orchestrator.site.Utils;
using nwrole.lib;

namespace nwrole.Orchestrator.site.Controllers
{
    public class ServiceController : Controller
    {
        public ActionResult Index(Guid id)
        {
            ServiceIndexViewModel viewModel = new ServiceIndexViewModel();
            
            using (TcpRelayChannel<IOrchestratorCtrlChannel> tcpRelayChannel = new TcpRelayChannel<IOrchestratorCtrlChannel>(SiteSettings.OrchestratorSBServiceNamespace, SiteSettings.OrchestratorSBServicePath, SiteSettings.OrchestratorSBIssuerName, SiteSettings.OrchestratorSBIssuerSecret))
            {
                viewModel.ServiceInfo = tcpRelayChannel.Channel.GetServiceInfo(id);
                viewModel.PluginsInfo = tcpRelayChannel.Channel.GetServicePluginsInfo(id);
            }

            if(viewModel.PluginsInfo == null)
                viewModel.PluginsInfo = new List<PluginInfo>();

            return View(viewModel);
        }

    }
}
